var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state:'',
    name:'',
    phone:'',
    address:'',
    productName:'',
    productImg:'',
    productMoney:"",
    productNumber:"",
    orderMoney:"",
    giveExpenses:"",
    total:"",
    time:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this
    wx.getStorage({
      key: 'openid',
      success: function(res) {
        let openid = res.data

        wx.request({
          url: app.globalData.URL + '/app/personalOrder/orderDetailed?id=' + options.id + '&type=' + options.type + '&openid=' + openid,
          success: function (res) {
            console.log(res.data)
            var pro_img = res.data.list[0].productImg
            WxParse.wxParse('pro_img', 'html', pro_img, that, 0);

            var total = Number(res.data.order.orderMoney) + Number(res.data.order.giveExpenses)

            var time = util.formatTime(res.data.order.createDate);

            that.setData({
              state: res.data.order.state,
              name: res.data.order.name,
              phone: res.data.order.tel,
              address: res.data.order.address + res.data.order.details,
              productName: res.data.list[0].productName,
              // productMoney: res.data.list[0].productMoney,
              productNumber: res.data.list[0].productNumber,
              orderMoney: res.data.order.orderMoney,
              giveExpenses: res.data.order.giveExpenses,
              total: total,
              time: time,
            })
          }
        })
      },
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  
  cancle: function (e) {
    console.log(e)
    var that = this
    wx.request({
      url: app.globalData.URL + '/app/personalOrder/orderType?state=-1&id=' + e.currentTarget.id,
      success: function (res) {
        console.log(res.data)
        if (res.data.flag == true) {
          wx.showToast({
            title: '取消成功',
            success: function () {
              wx.navigateBack({
                
              })
            }
          })
        }
      }
    })
  },


  toPay:function(){
    wx.navigateTo({
      url: '../pay/pay?id=' + that.data.ordId,
    })
  }
})